package KMeans;

import java.util.LinkedList;

/*
 * Data structure of a color combination
 */
public class CB {
	static int DEM = 5; // the number of regions of the color combination is set
						// to 5 right now
	LinkedList<Region> Rlist;
	int numR; // num of regionss
	private int label;// 1 means good and 0 means not good
	int tlabel;// temporary label used during the clustering
	int[][] nd; // neighbor distance, from left to right or up to down

	public CB() {// number of regions
		// TODO Auto-generated constructor stub
		Rlist = new LinkedList<Region>();
		numR = 0;
		this.label = 0;
		this.tlabel = 0;
		nd = new int[this.DEM - 1][3];

	}

	void distance_neighbor() {
		for (int i = 0; i < this.DEM - 1; i++) {
			nd[i][0] = Rlist.get(i).R - Rlist.get(i + 1).R;
			nd[i][1] = Rlist.get(i).G - Rlist.get(i + 1).G;
			nd[i][2] = Rlist.get(i).B - Rlist.get(i + 1).B;

		}
	}

	int getLabel() {
		return this.label;
	}

	void addRegion(int R, int G, int B) {
		Region r = new Region(R, G, B, numR);
		numR++;
		this.Rlist.add(r);
	}

	void randomAddRegion() {
		int r = Math.abs(Kmeans.rand.nextInt() % 256);
		int g = Math.abs(Kmeans.rand.nextInt() % 256);
		int b = Math.abs(Kmeans.rand.nextInt() % 256);
		Region rg = new Region(r, g, b, numR);
		numR++;
		this.Rlist.add(rg);
	}

	public void setLabel(int l) {
		this.label = l;
	}

	void show() {
		System.out
				.format("This color combination has %d regions \n", this.numR);
		for (int i = 0; i < numR; i++) {
			System.out.println("region " + i + " : ");
			System.out.format("R = %d, G = %d, B = %d", this.Rlist.get(i).R,
					this.Rlist.get(i).G, this.Rlist.get(i).B);
			System.out.println();
		}
	}

	void show_label() {
		System.out.println("true label is " + this.label + " cluster label: "
				+ tlabel);
	}
}
